import './detail.css';
import {connect} from 'react-redux';
import {Link} from 'react-router';
import Panel from './../../elements/Panel'
import {URL, md5Url} from '../../libs/Url';
import {Fetch} from '../../libs/';
import CONFIG from '../../libs/config';
import BreadcrumbNavigation from './../../components/BreadcrumbNavigation';

import {
    fetch,
    fetch_remove,
    enable_delete_btn,
    selectAllItem,
    selectItem,
} from '../../actions';
import {SUBJECT, PAGE_SUBJECT} from './../../actions/subject'
const Title = React.createClass({
    render(){
        return (
            <h1 className="text-center mtop35">{this.props.name}</h1>
        )
    }
})
const Des = React.createClass({
    render(){
        return (
            <p className="text-center auth-row">
                活动时间：{this.props.starttime} -- {this.props.endtime}
            </p>
        )
    }
});
const Detail = React.createClass({
    componentDidMount(){
        const {dispatch} = this.props;
        dispatch(fetch({
            url: URL.ACTIVITY_GET,
            campaignid: this.props.params.id
        }));

        // dispatch(fetch(SUBJECT.NEWS_DETAIL, {newsid: this.props.params.id,url:CONFIG.NEWS_PUSH_CLASS}))
    },
    render(){
        const {user} = this.props;
        const news = this.props[md5Url.ACTIVITY_GET] ? (this.props[md5Url.ACTIVITY_GET].campaign || {classList: user['class']}) : {classList: []};
        news.classList = news.classList || [];
        news.classList = (news.classList instanceof Array) ? news.classList : ['全部'];

        console.log(news.classList);
        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: CONFIG.MENUS_ABSOLUTE.HOME, label: '首页'},
                    {url: CONFIG.MENUS_ABSOLUTE.ACTIVITIES, label: '活动列表'},
                    {label: '正文'},
                ]}>
                </BreadcrumbNavigation>

                <Panel>
                    <div className="panel-body">
                        <Title {...news}></Title>
                        <Des {...news}/>
                        <div className="abstract"><b>摘要：</b>
                            {news.summary}
                        </div>
                        <div className="blog-img-wide">
                            <img src={URL.FUN_UPLOAD_PREVIEW(news.fileids)} alt=""/>
                        </div>
                        <div dangerouslySetInnerHTML={{__html: news.content}}></div>
                        <div className="blog-tags">
                            推送到的班级：
                            {
                                news.classList.map((item, index)=> {
                                    return <span key={index}>{item['class'] ? item['class'].name : item.name}</span>;
                                })
                            }
                        </div>
                    </div>
                </Panel>
            </div>
        )
    }
});
function select(state) {
    return {
        [md5Url.ACTIVITY_GET]: state.fetchBySubject[md5Url.ACTIVITY_GET],
        user: state.user.user,
    }
}
export default connect(select)(Detail)